#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/foreach.hpp>
#include <vector>
using namespace boost::property_tree;
using namespace std;
bool CreateJson(wstring &wstr)
{
    wstringstream wstream;
    try
    {
        wptree pt;
        pt.put(L"name",L"jim");
        wptree info;
        info.put(L"weight",L"50");
        wptree phone,phone_item1,phone_item2;
        phone_item1.put(L"phone",L"123");
        phone_item2.put(L"phone",L"123");
        phone.push_back(make_pair(L"",phone_item1));
        phone.push_back(make_pair(L"",phone_item2));
        info.put_child(L"all_phone",phone);
        pt.push_back(make_pair(L"info",info));
        write_json(wstream,pt);

    }
    catch(ptree_error pt)
    {
      pt.what();
      return false;
    }
    wstr = wstream.str();
    return true;
}
bool ParseJson(wstring &wstr)
{
    try
    {
        wptree pt;
        wstringstream wstream(wstr);
        read_json(wstream,pt);
        wstring wstrName = pt.get<wstring>(L"name");
        wptree info = pt.get_child(L"info");
        wstring weight = info.get<wstring>(L"weight");
        int w=0;
        w=info.get<int>(L"weight");
        wptree phones = info.get_child(L"all_phone");
        vector<wstring>vcPhone;
        BOOST_FOREACH(wptree::value_type &v,phones)
        {
            vcPhone.push_back(v.second.get<wstring>(L"phone"));
        }
    }
    catch(ptree_error pt)
    {
        pt.what();
        return false;
    }
    return true;
}
int main()
{
    wstring wstr;
    CreateJson(wstr);
    ParseJson(wstr);
    return 0;
}
